package cn.pa;

public class SyncTest implements Runnable {

  // 静态变量
  public static int TEST_INT = 0;

  // 被同步的实例方法
  public synchronized void increase() {
    while (TEST_INT < 100000) {
      TEST_INT++;
      System.out.println("increase:" + TEST_INT);
    }
  }

  @Override
  public void run() {
    increase();
  }

  public static void main(String[] args) throws InterruptedException {
    // 实例化对象
    SyncTest instance = new SyncTest();
    Thread t1 = new Thread(instance);
    Thread t2 = new Thread(instance);
    t1.start();
    t2.start();

    System.out.println("increase result:" + SyncTest.TEST_INT);
  }
}
